﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

using HsTec.Mobile.Green.Util;
using System.Collections.Generic;

public class Upload : IHttpHandler
{
    public Upload()
    {

    }
    #region IHttpHandler Members

    public bool IsReusable
    {
        get { return true; }
    }

    public void ProcessRequest(HttpContext context)
    {
        string sPath = String.Empty;
        if (context.Request.Files.Count > 0)
        {
            string tempFile = context.Request.PhysicalApplicationPath;
            for (int j = 0; j < context.Request.Files.Count; j++)
            {
                HttpPostedFile uploadFile = context.Request.Files[j];
                if (uploadFile.FileName.IndexOf("01") < 5)
                    sPath = "01";
                if (!Directory.Exists(Util.ServerPath + sPath))
                    Directory.CreateDirectory(Util.ServerPath + sPath);

                if (uploadFile.ContentLength > 0)
                {
                    uploadFile.SaveAs(Util.ServerPath + sPath + "\\" + uploadFile.FileName);
                }
            }
        }
    }
    #endregion
}
